/**
*item ....
*/
#include <cstdio>
#include <iostream>
#include <string>

using std::ostream;
using std::string;
using std::cout;

class Animial{
public:
	virtual Animial& operator=(const Animial& rhs){}
};

class Cat:public Animial{
public:
	virtual Cat& operator=(const Animial& rhs){
		const Cat& rhs_cat=dynamic_cast<const Cat&>(rhs);
		cout<<"assign animal to cat\n";
//		if(rhs_cat==NULL)
//			throw new std::bad_cast;
		*this=rhs;
		return *this;
	}
	Cat& operator=(const Cat& cat){
		*this=cat;
	}
};

class Employee{
public:
	Employee(string& name){
		this->name=name;
		tels=new string[TEL_COUNT];
	}
	Employee(Employee& e){
		this->name=e.name;
		cout<<"invoke copy constructor\n";
	}
	~Employee(){
		delete[] tels;
	}
	
	string name;
	const static int TEL_COUNT=1;
	string* tels;
	friend ostream& operator<<(ostream& s,Employee& e);
	
	static void *operator new(size_t size){
		cout<<"invoke my new\n";
		return malloc(size);
	}
	static void operator delete(void* p,size_t size){
		free(p);
	}
	
 	Employee& operator=(const Employee& e){
		cout<<"invoke operator =\n";
		this->name=e.name;
		return *this;
	}
};

ostream& operator<<(ostream& s,Employee& e){
	s<<e.name;
}

template<class T>
inline const T& max(const T& a,const T& b){
	return a>b?a:b;
}

int main(){
	char* hello=new char[5];
	delete[] hello;
	string name="liqiang";
	Employee e(name);
	Employee e2(name);
	e2=e;
	Employee *pe=new Employee(name);
	delete pe;
	pe=&e;

	cout<<e<<"\n";
	
	Animial ani1;
	Animial* pa=&ani1;
	Cat cat;
	Animial* pc=&cat;
	*pc=*pa;
	return 0;
}